<!-- Dom模板 -->
<template>
  <div class="login">
    <!-- Dom内容 -->
    <div class="nav">
      <div class="left">
        <h1>CRM订单管理系统</h1>
        <h3>Welcome to CRM System</h3>
      </div>
      <div class="right">
        <div class="cont">
          <div class="title">账号登录</div>
          <div class="con">
            <p>手机号</p>
            <input type="text" v-model="user" />
          </div>
          <div class="con">
            <p>输入密码</p>
            <input type="password" v-model="pass" />
          </div>
          <span class="span" v-if="strFlag">{{ str }}</span>
          <div class="con">
            <button @click="success">登录</button>
            <span @click="forget">忘记密码</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import a from './a'; // 引入组件
export default {
  name: "",
  data() {
    return {
      msg: "测试",
      navList: [],
      user: "",
      pass: "",
      strFlag: false,
      str: "",
    };
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    this.getNavList();
  },
  // Vue方法定义
  methods: {
    getNavList() {
      this.$store.dispatch("login/getNavList", {}).then((res) => {
        this.navList = res;
      });
      console.log(this.navList);
    },
    forget() {
      this.$router.push("/forgetPass");
    },
    success() {
      let un = false,
        pw = false;
      this.navList.forEach((item) => {
        if (item.user === this.user) {
          un = true;
          if (item.pass === this.pass) {
            pw = true;
          }
        }
        if (!un) {
          this.str = "账号不存在";
          this.strFlag = true;
        } else if (un && !pw) {
          this.str = "密码错误";
          this.strFlag = true;
        }
        if (item.user === this.user && item.pass === this.pass) {
          this.strFlag = false;
          console.log(item);
          sessionStorage.setItem("token", JSON.stringify(item));
          this.$router.push("/home");
          this.$router.go(0)
        }
      });
    },
  },
};
</script>

<style scoped>
/* @import url(''); 引入css类 */
* {
  padding: 0;
  margin: 0;
}
.span {
  color: red;
  position: absolute;
  bottom: 50px;
}
.login {
  width: 100%;
  height: 100%;
  position: fixed;
  background-color: white;
  z-index: 999;
  top: 0;
  left: 0;
}
.nav {
  display: flex;
  width: 1000px;
  box-shadow: 1px 1px 10px 5px gainsboro;
  position: fixed;
  top: 50%;
  left: 50%;
  margin-left: -500px;
  margin-top: -240px;
}
.left {
  width: 432px;
  height: 480px;
  background: linear-gradient(to right bottom, #a3d2ff, #50a8ff);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: white;
}
h3 {
  margin-top: 30px;
}
.right {
  width: calc(1000px - 432px);
  background-color: #eef1f5;
  height: 480px;
}
.cont {
  padding-left: 80px;
  padding-top: 60px;
  position: relative;
}
.title {
  margin-bottom: 50px;
  font-weight: bold;
}
.con {
  font-size: 14px;
  margin-top: 20px;
}
.con p {
  margin-bottom: 10px;
}
.con input {
  width: 352px;
  height: 36px;
  border: none;
  outline: none;
  padding-left: 10px;
}
.con button {
  width: 120px;
  height: 40px;
  margin-top: 20px;
  margin-right: 20px;
  border: none;
  background-color: #40a1ff;
  color: white;
}
.con span {
  font-size: 13px;
  color: gray;
}
</style>